<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src='/js/vue.js'></script>
    <div id='app'>

        <p>本次考试总成绩{{getTotalScore}}</p>
        <p>本次考试总成绩{{getTotalScore}}</p>
        <p>本次考试总成绩{{getTotalScore}}</p>

        <p>本次考试总成绩{{TotalScore}}</p>
        <p>本次考试总成绩{{TotalScore}}</p>
        <p>本次考试总成绩{{TotalScore}}</p>


    </div>
    <script>
        let app = new Vue({
            el:'#app',
            data:{
                msg:'hello word',
                score:[
                    {
                        id:1,
                        name:'语文',
                        score:86,
                    },

                    {
                        id:1,
                        name:'英语',
                        score:91,
                    },
                    {
                        id:1,
                        name:'数学',
                        score:95,
                    },
                ]
            },
            methods:{
                getTotalScore(){
                    let result = 0
                    for(item of this.scores){
                        result += subject.score
                        console.log("函数被调用")
                    }
                    return result
                }
            },
            // 计算属性有缓存，只需运算一次，效率非常高
            // computed计算属性以来vue实例的数据 只要其相关不改变 不会再次调用
            computed:{
                TotalScore(){
                    let result = 0
                    for(item of this.scores){
                        result += subject.score
                        console.log("计算逻辑被调用")
                    }
                    return result
                }
            }
        })
    </script>
</body>
</html>